package com.yztc.orangeentertainment.ui.main.findfragment.findmodel;

import com.yztc.orangeentertainment.bean.findbean.FindActivityBean;
import com.yztc.orangeentertainment.bean.findbean.FindBannerBean;
import com.yztc.orangeentertainment.bean.findbean.FindBean;
import com.yztc.orangeentertainment.bean.findbean.FindInteractBean;
import com.yztc.orangeentertainment.bean.findbean.FindStarBean;
import com.yztc.orangeentertainment.bean.findbean.FindStaractBean;
import com.yztc.orangeentertainment.bean.findbean.FindWewatchBean;
import com.yztc.orangeentertainment.ui.main.findfragment.findutils.FindConstant;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by My on 2016/10/6.
 */
public class FindModle implements IFindModle {

    @Override
    public void LoadFindData(String type, Map<String, String> map, final OnLoadFindListener
            loadFindListener) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(FindConstant.FindPath.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Call<FindBean> call = retrofit.create(RetrofitService.class).getNewAll(type, map);
        call.enqueue(new Callback<FindBean>() {
            @Override
            public void onResponse(Call<FindBean> call, Response<FindBean> response) {
                if (response.isSuccessful()) {
                    FindBean findBean = response.body();
                    List<FindBannerBean> findBannerBeens = findBean.getData().getBanner();
                    List<FindWewatchBean> wewatchBeens = findBean.getData().getWewatch();
                    List<FindInteractBean> interactBeens = findBean.getData().getInteract();
                    List<FindActivityBean> activityBeens = findBean.getData().getActivity();
                    List<FindStarBean> starBeens = findBean.getData().getStar();
                    FindStaractBean staractBean = findBean.getData().getStaract();
                    loadFindListener.onSuccess(findBannerBeens);
                    loadFindListener.getWewatchList(wewatchBeens);
                    loadFindListener.getInteractList(interactBeens);
                    loadFindListener.getActivityList(activityBeens);
                    loadFindListener.getStarList(starBeens);
                    loadFindListener.getStaract(staractBean);
                }
            }

            @Override
            public void onFailure(Call<FindBean> call, Throwable t) {
                loadFindListener.onFailure((Exception) t);
            }
        });
    }
}
